
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/24/2012 14:13:56
-- Generated from EDMX file: D:\Johnson\Healinker\Healiner.Entities\Healinker.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [School];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'DiseaseClassifications'
CREATE TABLE [dbo].[DiseaseClassifications] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ParentId] int  NOT NULL,
    [Name] nvarchar(255)  NOT NULL,
    [Order] int  NOT NULL,
    [CodeScope] nvarchar(100)  NOT NULL,
    [CodeClassificationId] int  NOT NULL,
    [QueryCode] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'CodeClassifications'
CREATE TABLE [dbo].[CodeClassifications] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(10)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Diseases'
CREATE TABLE [dbo].[Diseases] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DiseaseClassificationId] int  NOT NULL,
    [CodeClassificationId] int  NOT NULL,
    [Name] nvarchar(255)  NOT NULL,
    [ICDCode] nvarchar(20)  NOT NULL,
    [QueryCode] nvarchar(50)  NOT NULL,
    [AliasName] nvarchar(255)  NOT NULL
);
GO

-- Creating table 'DiseaseCauses'
CREATE TABLE [dbo].[DiseaseCauses] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DiseaseId] int  NOT NULL
);
GO

-- Creating table 'Treatments'
CREATE TABLE [dbo].[Treatments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DiseaseId] int  NOT NULL,
    [Summary] nvarchar(255)  NOT NULL,
    [Details] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Symptoms'
CREATE TABLE [dbo].[Symptoms] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'Medications'
CREATE TABLE [dbo].[Medications] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'LinkArticles'
CREATE TABLE [dbo].[LinkArticles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DiseaseId] int  NOT NULL,
    [Author] nvarchar(100)  NOT NULL,
    [FromSite] nvarchar(50)  NOT NULL,
    [PublishDate] datetime  NOT NULL,
    [Keywords] nvarchar(255)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Title] nvarchar(255)  NOT NULL
);
GO

-- Creating table 'DiseaseMedications'
CREATE TABLE [dbo].[DiseaseMedications] (
    [MedicationId] int  NOT NULL,
    [DiseaseId] int  NOT NULL
);
GO

-- Creating table 'DiseaseComplications'
CREATE TABLE [dbo].[DiseaseComplications] (
    [DiseaseId] int  NOT NULL,
    [ComplicationDiseaseId] int  NOT NULL
);
GO

-- Creating table 'DiseaseSymptoms'
CREATE TABLE [dbo].[DiseaseSymptoms] (
    [DiseaseId] int  NOT NULL,
    [SymptomId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'DiseaseClassifications'
ALTER TABLE [dbo].[DiseaseClassifications]
ADD CONSTRAINT [PK_DiseaseClassifications]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CodeClassifications'
ALTER TABLE [dbo].[CodeClassifications]
ADD CONSTRAINT [PK_CodeClassifications]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Diseases'
ALTER TABLE [dbo].[Diseases]
ADD CONSTRAINT [PK_Diseases]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DiseaseCauses'
ALTER TABLE [dbo].[DiseaseCauses]
ADD CONSTRAINT [PK_DiseaseCauses]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Treatments'
ALTER TABLE [dbo].[Treatments]
ADD CONSTRAINT [PK_Treatments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Symptoms'
ALTER TABLE [dbo].[Symptoms]
ADD CONSTRAINT [PK_Symptoms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Medications'
ALTER TABLE [dbo].[Medications]
ADD CONSTRAINT [PK_Medications]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'LinkArticles'
ALTER TABLE [dbo].[LinkArticles]
ADD CONSTRAINT [PK_LinkArticles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [DiseaseId], [MedicationId] in table 'DiseaseMedications'
ALTER TABLE [dbo].[DiseaseMedications]
ADD CONSTRAINT [PK_DiseaseMedications]
    PRIMARY KEY NONCLUSTERED ([DiseaseId], [MedicationId] ASC);
GO

-- Creating primary key on [ComplicationDiseaseId], [DiseaseId] in table 'DiseaseComplications'
ALTER TABLE [dbo].[DiseaseComplications]
ADD CONSTRAINT [PK_DiseaseComplications]
    PRIMARY KEY NONCLUSTERED ([ComplicationDiseaseId], [DiseaseId] ASC);
GO

-- Creating primary key on [DiseaseId], [SymptomId] in table 'DiseaseSymptoms'
ALTER TABLE [dbo].[DiseaseSymptoms]
ADD CONSTRAINT [PK_DiseaseSymptoms]
    PRIMARY KEY NONCLUSTERED ([DiseaseId], [SymptomId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CodeClassificationId] in table 'DiseaseClassifications'
ALTER TABLE [dbo].[DiseaseClassifications]
ADD CONSTRAINT [FK_DiseaseClassificationCodeClassification]
    FOREIGN KEY ([CodeClassificationId])
    REFERENCES [dbo].[CodeClassifications]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseClassificationCodeClassification'
CREATE INDEX [IX_FK_DiseaseClassificationCodeClassification]
ON [dbo].[DiseaseClassifications]
    ([CodeClassificationId]);
GO

-- Creating foreign key on [DiseaseClassificationId] in table 'Diseases'
ALTER TABLE [dbo].[Diseases]
ADD CONSTRAINT [FK_DiseaseDiseaseClassification]
    FOREIGN KEY ([DiseaseClassificationId])
    REFERENCES [dbo].[DiseaseClassifications]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseDiseaseClassification'
CREATE INDEX [IX_FK_DiseaseDiseaseClassification]
ON [dbo].[Diseases]
    ([DiseaseClassificationId]);
GO

-- Creating foreign key on [CodeClassificationId] in table 'Diseases'
ALTER TABLE [dbo].[Diseases]
ADD CONSTRAINT [FK_DiseaseCodeClassification]
    FOREIGN KEY ([CodeClassificationId])
    REFERENCES [dbo].[CodeClassifications]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseCodeClassification'
CREATE INDEX [IX_FK_DiseaseCodeClassification]
ON [dbo].[Diseases]
    ([CodeClassificationId]);
GO

-- Creating foreign key on [DiseaseId] in table 'DiseaseCauses'
ALTER TABLE [dbo].[DiseaseCauses]
ADD CONSTRAINT [FK_DiseaseDiseaseCause]
    FOREIGN KEY ([DiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseDiseaseCause'
CREATE INDEX [IX_FK_DiseaseDiseaseCause]
ON [dbo].[DiseaseCauses]
    ([DiseaseId]);
GO

-- Creating foreign key on [DiseaseId] in table 'Treatments'
ALTER TABLE [dbo].[Treatments]
ADD CONSTRAINT [FK_DiseaseTreatment]
    FOREIGN KEY ([DiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseTreatment'
CREATE INDEX [IX_FK_DiseaseTreatment]
ON [dbo].[Treatments]
    ([DiseaseId]);
GO

-- Creating foreign key on [DiseaseId] in table 'LinkArticles'
ALTER TABLE [dbo].[LinkArticles]
ADD CONSTRAINT [FK_DiseaseLinkArticle]
    FOREIGN KEY ([DiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseLinkArticle'
CREATE INDEX [IX_FK_DiseaseLinkArticle]
ON [dbo].[LinkArticles]
    ([DiseaseId]);
GO

-- Creating foreign key on [MedicationId] in table 'DiseaseMedications'
ALTER TABLE [dbo].[DiseaseMedications]
ADD CONSTRAINT [FK_MedicationDiseaseMedication]
    FOREIGN KEY ([MedicationId])
    REFERENCES [dbo].[Medications]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MedicationDiseaseMedication'
CREATE INDEX [IX_FK_MedicationDiseaseMedication]
ON [dbo].[DiseaseMedications]
    ([MedicationId]);
GO

-- Creating foreign key on [DiseaseId] in table 'DiseaseMedications'
ALTER TABLE [dbo].[DiseaseMedications]
ADD CONSTRAINT [FK_DiseaseDiseaseMedication]
    FOREIGN KEY ([DiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [DiseaseId] in table 'DiseaseComplications'
ALTER TABLE [dbo].[DiseaseComplications]
ADD CONSTRAINT [FK_DiseaseDiseaseComplication]
    FOREIGN KEY ([DiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseDiseaseComplication'
CREATE INDEX [IX_FK_DiseaseDiseaseComplication]
ON [dbo].[DiseaseComplications]
    ([DiseaseId]);
GO

-- Creating foreign key on [ComplicationDiseaseId] in table 'DiseaseComplications'
ALTER TABLE [dbo].[DiseaseComplications]
ADD CONSTRAINT [FK_DiseaseDiseaseComplication1]
    FOREIGN KEY ([ComplicationDiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [DiseaseId] in table 'DiseaseSymptoms'
ALTER TABLE [dbo].[DiseaseSymptoms]
ADD CONSTRAINT [FK_DiseaseDiseaseSymptom]
    FOREIGN KEY ([DiseaseId])
    REFERENCES [dbo].[Diseases]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [SymptomId] in table 'DiseaseSymptoms'
ALTER TABLE [dbo].[DiseaseSymptoms]
ADD CONSTRAINT [FK_SymptomDiseaseSymptom]
    FOREIGN KEY ([SymptomId])
    REFERENCES [dbo].[Symptoms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SymptomDiseaseSymptom'
CREATE INDEX [IX_FK_SymptomDiseaseSymptom]
ON [dbo].[DiseaseSymptoms]
    ([SymptomId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------